/*
 * Copyright Hundsun Technologies Inc. All Rights Reserved.
 */

package main

import (
	"log"

	rabbitmq "hundsun.com/hsl/hschain/store/mq/rabbitmq"
)

func producer() {
	conf := rabbitmq.Config{
		Host:     "10.20.66.189",
		Port:     5672,
		Username: "admin",
		Password: "hs600570",
		Vhost:    "/",
	}
	connection, err := rabbitmq.NewAMQPConnection(conf)
	if err != nil {
		log.Panic(err)
	}

	connection.Use(rabbitmq.ExchangeDeclare("exchange_test", rabbitmq.ExchangeDirect, nil))
	connection.Use(rabbitmq.QueueDeclare("test", nil))
	connection.Use(rabbitmq.QueueBind("test", "", "exchange_test", false, nil))
	if err := connection.Run(); err != nil {
		log.Panic(err)
	}

	producer := rabbitmq.NewProducer("exchange_test", "", "", connection)
	err = producer.Publish([]byte(`{"Name":"Alice","Body":"Hello","Time":1294706395881547000}`))
	if err != nil {
		log.Println("unable to publish body")
	}
}
